package com.hbnu.system.controller;

import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.PatentDTO;
import com.hbnu.system.model.entity.Patent;
import com.hbnu.system.model.entity.Patentfile;
import com.hbnu.system.model.query.PatentPageQuery;
import com.hbnu.system.model.vo.PatentVO;
import com.hbnu.system.service.IPatentService;
import com.hbnu.system.service.PatentfileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/patent")
@Api(tags = "专利模块")
public class PatentController {

    @Autowired
    IPatentService iPatentService;
    @Autowired
    PatentfileService patentfileService;

    @ApiOperation("专利-正式录入")
    @PostMapping("/addPatent")
    public Rest<Boolean> AddPatent(@RequestBody PatentDTO patentdto){
        boolean add = iPatentService.addPatent(patentdto);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("专利-删除")
    @GetMapping("/deletePatent")
    public Rest<Boolean> deletePatent(String patentID) throws IOException {
        boolean delete = iPatentService.deletePatent(patentID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("专利-名称查重")
    @GetMapping("/CheckPatentName")
    public Rest<Boolean> CheckPatentName(String patent_name){
        boolean check = iPatentService.checkPatentName(patent_name);
        return check ? Rest.success() : Rest.failed();
    }

    @ApiOperation("专利-修改")
    @PostMapping("/UpdatePatent")
    public Rest<Boolean> UpdatePatent(@RequestBody Patent patent){
        boolean update = iPatentService.updatePatent(patent);
        return update ? Rest.success() : Rest.failed();
    }



    @ApiOperation("根据主键专利DTO查询")
    @GetMapping("/GetPatentDTOById")
    public Rest<PatentDTO> GetPatentDTOById(String patentID){
        PatentDTO patentdto = iPatentService.getPatentDTOById(patentID);
        return Rest.success(patentdto);
    }

    @ApiOperation("专利-院级通过")
    @GetMapping("/CollegeCheckPass")
    public Rest<String> CollegePassPaper(@RequestHeader("X-Token") String token,String PaID){
        Boolean b = iPatentService.collegeCheckPass(token ,PaID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("专利-院级打回")
    @PostMapping("/CollegeCheckBack")
    public Rest<String> CollegeBackPaper(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPatentService.collegeCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("专利-校级通过")
    @GetMapping("/SchoolCheckPass")
    public Rest<String> SchoolPassPaper(@RequestHeader("X-Token") String token,String PaID){
        Boolean b = iPatentService.schoolCheckPass(token,PaID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("专利-校级打回")
    @PostMapping("/SchoolCheckBack")
    public Rest<String> SchoolBackPaper(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iPatentService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("专利-提交")
    @PostMapping("/ReCommitPatent")
    public Rest<Boolean> ReCommitPatent(String patentID){
        boolean add = iPatentService.ReCommitPatent(patentID);
        return add ? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("专利-撤回")
    @GetMapping("/WithdrawPatent")
    public Rest<Boolean> WithdrawPatent(String patentID){
        boolean withdraw = iPatentService.withdrawPatent(patentID);
        return withdraw ? Rest.success() : Rest.failed();
    }

    @ApiOperation("用户获取与自己相关的专利-分页")
    @PostMapping("/UserGetRelatePatent")
    public Rest<CommonPage<PatentVO>> UserGetRelatePatent(@RequestBody PatentPageQuery patentPageQuery){
        CommonPage<PatentVO> patentVOCommonPage = iPatentService.userGetRelatePatent(patentPageQuery);
        return Rest.success(patentVOCommonPage);
    }

    @ApiOperation("专利导出")
    @PostMapping("export")
    public Rest<CommonPage<Patent>> export(@RequestBody PatentPageQuery patentPageQuery) {
        CommonPage<Patent> patentCommonPage = iPatentService.export(patentPageQuery);
        return Rest.success(patentCommonPage);
    }


    @ApiOperation("专利-文件信息上传")
    @PostMapping("/addpatentfile")
    public Rest<Boolean> addpatentfile(@RequestBody Patentfile patentfile){
        boolean add = patentfileService.addPatentfile(patentfile);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("专利-文件信息删除")
    @GetMapping("/Deletepatentfile")
    public Rest<Boolean> Deletepatentfile(String id)throws IOException {
        boolean delete = patentfileService.deletPatentfile(id);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("专利-文件信息分页查询")
    @GetMapping ("/pagepatentfileCondition")
    public Rest<List<Patentfile>> pagepatentfileConditionfile(String id){
        List<Patentfile> page = patentfileService.pagePatentfile(id);
        return Rest.success(page);
    }
}

